<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-9-7
 * Time: 下午5:14
 */
define('CLASS_PATH', '/var/www/html/new/d/class/');
include '/var/www/html/new/com.inc.php';
include CLASS_PATH . 'Api.class.php';
include CLASS_PATH . 'Coupon.class.php';

$coupon = new \PFT\Coupon($_SESSION['memberID'], $apply_did);
switch ($action) {
    case 'coupon_list':
        //获取自己已领取的优惠券
        $coupon_status = intval($_GET['status']);
        $data = $coupon->lists($coupon_status);
        if (!$data) {
            Api::Response('目前还没有领取到优惠券', Api::noContentCode);
        }
        Api::CollectionResponse($data);
        break;
    //查看优惠券的领取情况
    case 'collection_list':
        $coupon_id = intval($_POST['coupon_id']);
        $data = $coupon->collection_list($coupon_id);
        if (count($data['list'])==0) {
            Api::Response('优惠券没有被领取过', Api::noContentCode);
        }
        Api::CollectionResponse($data);
        break;
    case 'shop_coupons':
        //查询店铺优惠券列表
        $data = $coupon->shop_coupons();
        if (!$data) {
            Api::Response('目前还没可领取的优惠券', Api::noContentCode);
        }
        Api::CollectionResponse($data);
        break;
    case 'collect_coupon':
        $coupon_id = intval($_POST['coupon']);
        $data = $coupon->collect_coupon($coupon_id);
        Api::Response($data['msg'], $data['code']);
        break;
    case 'collect_detail':
        //优惠券详情
        $coupon_id = intval($_GET['coupon_id']);
        $data = $coupon->detail($coupon_id);
        Api::CollectionResponse($data);
        break;
}
